﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security;

using SharedGenomics.Workbench.Core;

namespace SharedGenomics.Workbench.Views.WindowsForms
{
    public partial class LoginForm : View, ILoginView
    {
        #region Constructors

        public LoginForm()
        {
            InitializeComponent();

            //add empty handler to loginStarted event
            this.LoginStarted += delegate { };
        }

        #endregion

        #region Protected Methods

        protected void OnLoginStarted(EventArgs e)
        {
            this.LoginStarted(this, e);
        }

        #endregion

        #region Event Handlers

        private void btLogin_Click(object sender, EventArgs e)
        {
            this.OnLoginStarted(EventArgs.Empty);
        }

        #endregion

        #region ILoginView Members

        public string Username
        {
            get { return this.txtUsername.Text; }
        }

        public System.Security.SecureString Password
        {
            get { return this.stbPassword.SecureText; }
        }

        public string LoginMessage
        {
            set
            {
                this.lbLoginInfo.Invoke(new Action(() =>
                    {
                        this.lbLoginInfo.Text = value;
                        this.lbLoginInfo.Visible = true;
                    }));
            }
        }

        public bool LoginEnabled
        {
            set { this.btLogin.Invoke(new Action(() => this.btLogin.Enabled = value)); }
        }

        public bool IsProgressBarVisible
        {
            get { return this.pgbLogin.Visible; }
            set { this.pgbLogin.Invoke(new Action(() => this.pgbLogin.Visible = value)); }
        }

        public event EventHandler LoginStarted;

        #endregion
    }
}
